<?php $this->import('Header'); ?>
<div class="btn-toolbar">
	<a href="/Article/AddCategory" class="btn btn-primary"><i class="icon-plus"></i> 添加</a>
</div>
<div class="well">
	<div class="tab-content">
		<table class="table">
			<tr>
				<td>Id</td>
				<td>分类名称</td>
				<td>排序</td>
				<td style="width: 160px;">操作</td>
			</tr>
			<?php
				function show($all, $i) {
					foreach ($all as $arr) {
						$tmp = '';
						if ($i) {
							$tmp = implode('', array_fill(0, $i * 8, '&nbsp;'));
						}
						?>

						<tr>
							<td><?php echo $tmp . $arr['CategoryId'] ?></td>
							<td><?php echo $tmp . $arr['CategoryName'] ?></td>
							<td><?php echo $tmp . $arr['Sort']?></td>
							<td>
								<a href="javascript:;" onclick="del(<?php echo $arr['CategoryId'] ?>)" class="btn">删除</a>
								<a href="/Article/AddCategory?id=<?php echo $arr['CategoryId'] ?>" class="btn">修改</a>
							</td>
						</tr>
						<?php
							if (!empty($arr['List'])) {
								show($arr['List'], $i + 1);
							}
						?>
					<?php }
				}
				show($all, 0);
			?>
		</table>
	</div>
</div>
<?php $this->import('Footer'); ?>
<script>
	function del(id) {
		if (!confirm('确定要删除分类？删除的话下面的文章将不能正常显示')) {
			return;
		}
		$.ajax({
			url: '/Ajax/Article/delCategory?stmp=' + new Date().toString(),
			type: 'get',
			data: {id: id},
			dataType: 'json',
			success: function(d) {
				if (d.error) {
					alert(d.data);
				} else {
					window.location.reload();
				}
			}
		});
	}
</script>